﻿using System;

namespace Company.Infrastructure
{
    public static class DateTimeExtension
    {
        private static readonly DateTime MinDate = new DateTime(1900, 1, 1);
        private static readonly DateTime MaxDate = new DateTime(9999, 12, 31, 23, 59, 59, 999);

        public static bool IsValid(this DateTime target)
        {
            return (target >= MinDate) && (target <= MaxDate);
        }
        public static string ToDayFormatted(this DateTime d)
        {
            //string aa = d.Month.ToString("00") + d.Day.ToString("00") + d.Year.ToString("0000");
            string aa = d.Month.ToString("00") + "/" + d.Day.ToString("00") + "/" + d.Year.ToString("0000");
            return aa;
        }
        /// <summary>
        /// to be used on dates querys as the begining
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public static DateTime GetDateOnlyFrom(this DateTime target)
        {
            DateTime tmp = new DateTime(target.Year, target.Month, target.Day);

            return tmp;
        }
        /// <summary>
        /// it will return the day , but with the max time as the second parameter
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public static DateTime GetDateOnlyTo(this DateTime target)
        {
            DateTime tmp = new DateTime(target.Year, target.Month, target.Day, 23, 59, 59, 997);
            return tmp;
        }
    }
}
